import React, { FC, useMemo } from "react";
import { Input, Spin } from "antd";

interface TempInputProps {
    ds: any,
    value: string,
    spinning: boolean,
    disabled: boolean
};

const TempInput: FC<TempInputProps> = (props) => {

    const renderTempInput: any = useMemo(() => {
        let { ds = {}, value, spinning, disabled }: { ds: any, value: string, spinning: boolean, disabled: boolean } = props;
        if (value != ds.value) {
            return (
                <Spin size="small" spinning={!!spinning}>
                    <Input key={"showInput"} disabled={disabled} readOnly={true} value={value} />
                </Spin>
            );
        }
        return (
            <Spin size="small" spinning={!!spinning}>
                <Input key='showInput' disabled={disabled} readOnly={true} value={ds.text || ds.value || value} />
            </Spin>
        );
    }, [props])

    return (renderTempInput)
};

export default TempInput; 